package com.mooc.lib_sofa.adapter

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter

class SofaVpAdapter (title : ArrayList<String>,v : ArrayList<View>):PagerAdapter() {

    var titles : ArrayList<String>
    var views : ArrayList<View>
    init {
        titles = title
        views = v
    }

    //配置flycotab标题内容
    override fun getPageTitle(position: Int): CharSequence? {
        return titles[position]
    }

    override fun getCount(): Int {
        return views.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val lp = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT)
        views[position].layoutParams = lp
        container.addView(views[position])
        return views[position]
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        val view : View = `object` as View
        container.removeView(view)
    }

}